package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetUserLogonRequest;
import keeto.com.vn.bms.network.response.GetUserLogonResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskUserLogon extends AbstractTask{

	String userName;
	String passWord;
	
	public TaskUserLogon(BMSListener listener, IBMSCore core,String username,String password) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.userName = username;
		this.passWord = password;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetUserLogonRequest request = new GetUserLogonRequest();
		request.setUserName(userName);
		request.setPassWord(passWord);
		GetUserLogonResponse response = protocol.getLogon(request);
		for (BMSListener mlistener : listener){
			mlistener.finishLogon(response.getReturnCode(), response.getUserModel());
		}
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishLogon(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null);
		}
	}

}
